package com.wude.guild.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.mc.developmentkit.utils.ToastUtil;
import com.umeng.analytics.MobclickAgent;
import com.wude.guild.ForgetPassActivity;
import com.wude.guild.R;
import com.wude.guild.servercore.app.CubeFragment;
import com.wude.tools.ViewUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 忘记密码 输入密码  新密码
 * Created by Administrator on 2017/3/28.
 */

public class ForgetPassOneFragment extends CubeFragment implements View.OnClickListener {
    private EditText onePass;
    private EditText twePass;
    private TextView next;

    private ForgetPassActivity activity;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_forgetpass, null);
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("ForgetPassOneFragment");
    }

    @Override
    public void onPause() {
        super.onPause();

        MobclickAgent.onPageEnd("ForgetPassOneFragment");
    }

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_forgetpass, null);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        onePass = findView(view, R.id.onePass);
        twePass = findView(view, R.id.twePass);
        next = findView(view, R.id.next);

//        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

        next.setOnClickListener(this);
        ViewUtils.setEditTextInhibitInputSpace(onePass);
        ViewUtils.setEditTextInhibitInputSpace(twePass);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.activity = (ForgetPassActivity) activity;
    }

    public void onClick() {
        String onepass = onePass.getText().toString();
        String twepass = twePass.getText().toString();
        int length = onePass.getText().length();
        if (onepass.equals("")) {
            ToastUtil.showToast("请输入新密码");
            return;
        }
        if (twepass.equals("")) {
            ToastUtil.showToast("请再次输入新密码");
            return;
        }
        if (length > 12) {
            ToastUtil.showToast("密码长度大于12位字符");
            return;
        }
        if (length < 6) {
            ToastUtil.showToast("密码长度小于6位字符");
            return;
        }
        if (!onepass.equals(twepass)) {
            ToastUtil.showToast("两次密码不一致");
            return;
        }

        activity.pushFragmentToBackStack(ForgetPassTweFragment.class, onepass);
//        activity.setOnePass(onepass);
//        activity.setNumberPages(1);
    }

    @Override
    public void onClick(View view) {
        onClick();
    }
}
